//引入一级路由组件
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级路由组件
import MyOrder from '@/pages/Center/MyOrder'
import GroupOrder from '@/pages/Center/GroupOrder'

export default [
    {
        path: "/home",
        component: Home,
        meta: { showFooter: true }
    },
    {
        path: "/search/:keyword?",
        component: Search,
        meta: { showFooter: true },
        name: 'search',
    },
    {
        path: "/login",
        component: Login,
        meta: { showFooter: false }
    },
    {
        path: "/register",
        component: Register,
        meta: { showFooter: false }
    },
    {
        path: "/detail/:skuid",
        component: Detail,
        meta: { showFooter: true }
    },
    {
        path: "/addcartsuccess",
        component: AddCartSuccess,
        name: 'addcartsuccess',
        meta: { showFooter: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path.indexOf('/detail/')!=-1 || from.path.indexOf('/login')!=-1) {
                next()
            }else {
                next(false)
            }
        },
        
        
    },
    {
        path: "/shopcart",
        component: ShopCart,
        name: 'shopcart',
        meta: { showFooter: true }
    },
    {
        path: "/trade",
        component: Trade,
        name: 'trade',
        meta: { showFooter: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false)
            }
        },
    },
    {
        path: "/pay",
        component: Pay,
        name: 'pay',
        meta: { showFooter: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        },
    },
    {
        path: "/paysuccess",
        component: PaySuccess,
        name: 'paysuccess',
        meta: { showFooter: true },
        
    },
    {
        path: "/center",
        component: Center,
        name: 'center',
        meta: { showFooter: true },
        //二级路由
        children: [
            {
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            //重定向
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ],
    },
    //重定向
    {
        path: "*",
        redirect: "/home"
    }

]